package com.toocms.jinjuhang.ui.commodity.ration

import android.app.Application
import androidx.core.graphics.drawable.DrawableCompat
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableField
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.ResourceUtils
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.BR
import com.toocms.jinjuhang.config.Constants
import com.toocms.tab.base.BaseModel
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.MultiItemViewModel
import com.toocms.tab.binding.ItemBinding
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class RationModel(application: Application) : BaseViewModel<BaseModel>(application) {
    val backIconObservableField by lazy {
        val rawDrawable = ResourceUtils.getDrawable(R.mipmap.icon_arrow_left_black).mutate()
        DrawableCompat.setTint(
            rawDrawable,
            ColorUtils.getColor(com.toocms.tab.R.color.qmui_config_color_white)
        )
        ObservableField(rawDrawable)
    }

    val backClickBindingCommand = BindingCommand<BindingAction>(this::finishFragment)

    val items = ObservableArrayList<MultiItemViewModel<*>>()

    val itemBinding = ItemBinding.of<MultiItemViewModel<*>> { itemBinding, _, item ->
        when (item.itemType) {
            Constants.RecyclerViewItemType.ITEM_TYPE_ZERO -> itemBinding.set(
                BR.rationTopItemModel,
                R.layout.item_ration_top
            )
            Constants.RecyclerViewItemType.ITEM_TYPE_ONE -> itemBinding.set(
                BR.rationItemModel,
                R.layout.item_ration
            )
        }
    }

    init {
        items += RationTopItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
        items += RationItemModel(this)
    }

}